package com.supermap.fabricsdk;

import java.util.UUID;
import java.util.logging.Logger;

/**
 * @author liqs
 * @version 1.0
 * @date 2020/8/7 9:11
 */
public class SmTestThreadRead extends Thread {

    Logger logger = Logger.getLogger(SmTestThreadWrite.class.getName());
    private SmChain smChain;
    private String chaincodeName;
    private int number;
    private int threadCount;
    private int start;
    private String key;

    public SmTestThreadRead(SmChain smChain, String chaincodeName, int number, int i , int start, String key) {
        this.smChain = smChain;
        this.chaincodeName = chaincodeName;
        this.number = number;
        this.threadCount = i;
        this.start = start;
        this.key = key;
    }

    @Override
    public void run() {
        String result = null;
        for (int i = start; i < start + number; i++) {
            result = smChain.getTransaction().queryByString(
                    chaincodeName,
                    "GetRecordByKey",
                    new String[]{key}
            );
            if (result.length() == 0) {
                logger.info("Read data on chain FAILED! MESSAGE:" + result);
            }
        }
        System.out.println("执行完第" + this.threadCount + "线程");
    }
}
